package org.jrfe.gfx.g2d.shapes;

import org.jrfe.JRFE;
import org.jrfe.gfx.Vertex;
import org.jrfe.math.Vector2f;
import org.jrfe.util.FastMath;

public class Circle extends AbstractShape {

	protected float radius;
	protected int samples;
	
	
	public Circle(Vector2f loc,float radius,int samples) {
		super(samples * 4 + 2,loc,0,new Vector2f(),JRFE.PrimitiveTypes.TRIANGLE_FAN);
		
		this.radius = radius;
		this.samples = samples;
			
		Vertex v = new  Vertex();
		v.a = 1;
		v.r = 1;
		v.b = 1;
		v.g = 1;
		
		v.x = 0;
		v.y = 0;
		v.s = 0.5f;
		v.t = 0.5f;
		getBatch().update(0, v);
		
		float d = radius * 2;
		float ta = 1.f / d;
		
		
		int n = samples * 4;
		float a = 360.f / n;
		
		for(int i = 0; i < n + 1; i++ ){
			float r = i * a;
			float cos = FastMath.cos(r * FastMath.DEG_TO_RAD);
			float sin = FastMath.sin(r * FastMath.DEG_TO_RAD);
			
			float  tx = radius * cos;// - y * sin;
			float  ty = radius * sin;// + y * cos;
			
			v.x = tx;
			v.y =  ty;
			v.s = (tx + radius) * ta;
			v.t = 1.f - (ty + radius) * ta;
			getBatch().update(i+1, v);
			
					
		}
		
		// TODO Auto-generated constructor stub
	}

	@Override
	public void updateTextureCords() {
		// TODO Auto-generated method stub
		super.updateTextureCords();
	}
}
